<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>HexUtil</title>
    <link href="../../css/common.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<input type="file" id="file">
</body>
<script src="../../../lib/baitu.min.js"></script>
<script>
    const {HexUtil} = Baitu
    console.log(HexUtil.encode(''))
    const encodeStr = HexUtil.encode("百涂工具");
    console.log("编码：", encodeStr);
    const decodeStr = HexUtil.decode(encodeStr);
    console.log("解码：", decodeStr);

    const fileInput = document.querySelector("#file");
    fileInput.onchange = () => {
        const file = fileInput.files[0];
        console.log(file)
        if (file) {
            // 使用FileUtil获取Buffer
            FileUtil.getFileBuffer(file, 100).then(res => {
                // Buffer转Hex
                const bufferHex = HexUtil.arrayBufferToHex(res);
                console.log(bufferHex);
            });
            // 使用FileUtil获取uint8
            FileUtil.getUint8Array(file, 100).then(uintRes => {
                console.log("uint8：", uintRes);
                const uint8Hex = HexUtil.uint8ArrayToHex(uintRes);
                console.log(uint8Hex);
                const uint8 = HexUtil.hexToUint8Array(uint8Hex);
                console.log(uint8);
            })
            // 上面的因为是同一个文件，bufferHex和uint8Hex、uintRes和uint8最终结果应该是一致的
        }
    }
</script>
</html>
